<?php
namespace Smanage\Controller;
use Common\Controller\AdminbaseController;
class SimportadminController extends AdminbaseController {
     function _initialize() {
			parent::_initialize();
							
		}
    
    /**
     *
     * 显示导入页面 ...
     */
    public function import()
    {
        $this->display();
    }
    /**实现导入excel
     **/
    function impUser(){
        if (!empty($_FILES)) {
            $upload = new \Think\Upload();// 实例化上传类
            $filepath='./data/upload/';  //设置附件目录
            $upload->exts = array('xlsx','xls');// 设置附件上传类型
            $upload->rootPath  =  $filepath; // 设置附件上传根目录
            $upload->saveName  =     'time';
            $upload->autoSub   =     false; //是否创建子目录
            if (!$info=$upload->upload()) {
                $this->error($upload->getError());
            }
            foreach ($info as $key => $value) {
                unset($info);
                $info[0]=$value;
                $info[0]['savepath']=$filepath;
            }
            vendor("PHPExcel.PHPExcel");
            $file_name=$info[0]['savepath'].$info[0]['savename'];
            $objReader = \PHPExcel_IOFactory::createReader('Excel5');
            $objPHPExcel = $objReader->load($file_name,$encode='utf-8');
            $sheet = $objPHPExcel->getSheet(0);
            $highestRow = $sheet->getHighestRow(); // 取得总行数
            $highestColumn = $sheet->getHighestColumn(); // 取得总列数
            $j=0;
            for($i=3;$i<=$highestRow;$i++)
            {
                $data['sblb'] = $objPHPExcel->getActiveSheet()->getCell("A".$i)->getValue();
				$data['sydw'] = $objPHPExcel->getActiveSheet()->getCell("B".$i)->getValue();
				$data['sbxh']= $objPHPExcel->getActiveSheet()->getCell("C".$i)->getValue();
				$data['sbsn']= $objPHPExcel->getActiveSheet()->getCell("D".$i)->getValue();
				$data['sbpp']= $objPHPExcel->getActiveSheet()->getCell("E".$i)->getValue();
				$data['gzrq']= $objPHPExcel->getActiveSheet()->getCell("F".$i)->getValue();
				$data['sbwhr']= $objPHPExcel->getActiveSheet()->getCell("H".$i)->getValue();
				$data['sbyz']= $objPHPExcel->getActiveSheet()->getCell("I".$i)->getValue();
				$data['cfdd']= $objPHPExcel->getActiveSheet()->getCell("J".$i)->getValue();
				$data['lyr']= $objPHPExcel->getActiveSheet()->getCell("K".$i)->getValue();
				$data['sbzt']= $objPHPExcel->getActiveSheet()->getCell("L".$i)->getValue();
				$data['ipadd']= $objPHPExcel->getActiveSheet()->getCell("M".$i)->getValue();
                $data['addon']= $objPHPExcel->getActiveSheet()->getCell("N".$i)->getValue();
                    M('Smanage')->add($data);
                    $j++;                
            }
            //unlink($file_name); //删除上传的文件
            //User_log('批量导入联系人，数量：'.$j);
            $this->success('导入成功！本次导入设备数量：'.$j);
        }else
        {
            $this->error("请选择上传的文件");
        }
    }
}

?>